const App = getApp();
// 工具类
import Util from '../../../utils/util.js';
Page({
  /**
   * 页面的初始数据
   */
  onShareAppMessage() {
    return {
      title: 'picker-view',
      path: 'page/component/pages/picker-view/picker-view'
    }
  },
  data: {
    isLogin: false,
    info: {}, // 商会信息
    manager:[],// 商会所有管理
    user:[],   // 商会普通成员
    maoHao: '：',
    showStatus:false,
    showTitle:"设置商会管理员",
    showType:1,//1设置商会管理员，2升级人数
    good_grade:[],
    scrollHeight: null,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    that.setData({
      isLogin: App.checkIsLogin()
    });
    if (that.data.isLogin) {
      //获取服务队
      // that.setData({
      //   teamId: App.checkTeam()
      // });
      // 获取信息
      that.getDetail();
      //设置列表高度
      that.setListHeight()
    }
  },

  /**
   * 获取信息
   */
  getDetail() {
    let that = this;
    App._get('apply/get_shanghui', {}, function(result) {
      
      that.setData({
        info:result.data.shanghui,
        manager:result.data.manager,
        user:result.data.user,
        good_grade:result.data.good_grade,
      });
    });
  },

  //提交
  formSubmit(e) {
    var formData=e.detail.value;//获取表单数据
    let obj = {
      wx_mchid:formData.wx_mchid,
      wx_apikey:formData.wx_apikey,
      wx_apiclient_cert:formData.wx_apiclient_cert,
      wx_apiclient_key:formData.wx_apiclient_key,
    };
    console.log(obj);
    let _this = this;
    App._post_form('apply/edit_shanghui', obj, result => {
      //成功提示
      App.showSuccess(result.msg);
    });
  },
  // 弹窗
  apply_on(e){
    let that = this;
    let showType = e.currentTarget.dataset.type;
    let showTitle = '设置商会管理员';
    // 升级商会
    if(showType == 2){showTitle = '升级商会';}
    that.setData({showStatus: true,showTitle,showType}); 
  },
  //关闭弹窗
  closeBh(){
    let that = this;
    that.setData({
      showStatus: false,
    }); 
  },
  //设置管理
  pass(e){
    let id = e.currentTarget.dataset.id;
    let obj = {user_id:id,grade_id:10009}
    let _this = this;
    App._post_form('apply/edit_manager', obj, result => {
      _this.closeBh();
      //成功提示
      App.showSuccess(result.msg, function() {
        _this.getDetail();
      });
    });
  },
  // 购买升级
  buy(e){
    let that = this;
    let obj = e.currentTarget.dataset.id;
    App._post_form('shanghui/buy', obj, result => {
      that.closeBh();
      //成功提示
      App.showSuccess(result.msg.success,function(){
        that.getDetail();
      });
    });
  },
  
  //设置列表高度
  setListHeight() {
    let systemInfo = wx.getSystemInfoSync(),
      rpx = systemInfo.windowWidth / 750, // 计算rpx
      tapHeight = Math.floor(rpx * 98), // tap高度
      scrollHeight = systemInfo.windowHeight - tapHeight; // swiper高度
    this.setData({
      scrollHeight
    });
  },

})                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          